package test_3_13;

import java.util.Scanner;

public class four {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7};
        System.out.println("请输入你要查询的数字：");
        Scanner sc=new Scanner(System.in);
        int key=sc.nextInt();
        int c=find_key(arr,key);
        if(c>=0)
        {
            System.out.println("找到了");
        }
        else
        {
            System.out.println("找不到");
        }

    }
    public static int find_key(int[]arr,int key)
    {
        int left=0;
        int right=arr.length-1;
        while(left<=right)
        {
            int mid=(left+right)/2;
            if(key>arr[mid])
            {
                left=mid+1;
            }
            else if(key<arr[mid])
            {
                right=mid-1;
            }
            else {
                return 1;
            }
        }
        return -1;
    }
}
